﻿Imports System.Data.OleDb
Imports System.Data
Partial Class ResourcesAdd
    Inherits System.Web.UI.Page

    Protected Sub btnSubmit_Click(sender As Object, e As System.EventArgs) Handles btnSubmit.Click

        Dim myGUID As System.Guid
        myGUID = Guid.NewGuid()
        Dim newFileName = myGUID.ToString() + ".jpg"

        If R_Image.HasFile Then
            Dim picLocationOnServerHardDisk = Request.MapPath("pix") & "/" & newFileName
            R_Image.SaveAs(picLocationOnServerHardDisk)
        End If

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("myFirstDatabase").ConnectionString)
        Dim SqlString As String = "Insert into tblresources(RName,RLocation,RQuantity,RAddress,RPicture) Values (@f1,@f2,@f3,@f4,@f5)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", txtRname.Text)
        cmd.Parameters.AddWithValue("@f2", txtRLocation.Text)
        cmd.Parameters.AddWithValue("@f3", txtQuantity.Text)
        cmd.Parameters.AddWithValue("@f4", txtRAddress.Text)
        cmd.Parameters.AddWithValue("@f5", "pix/" & R_Image.FileName)
        oleDbConn.Open()
        cmd.ExecuteNonQuery()
        Response.Redirect("ResourceAddSuccess.aspx")
    End Sub
End Class
